/**
 * related to categoryCell.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-12-28
 */
var app = sm("do_App");
var page = sm("do_Page");
var root=ui("$");
var nf = sm("do_Notification");
var openHelper = require("helper/open");
var listdataTabs = mm("do_ListData");
var aLayout_goCateGrid = ui("aLayout_goCateGrid");

var do_SegmentView_1 = ui("do_SegmentView_1");
var jsonTabs = [];

page.on("ShopSelectOneTab", function(data){
	var _selectedIndex=-1;
	for(var i=0; i<jsonTabs.length;i++){
		if (jsonTabs[i].categoryId == data.categoryId){
			_selectedIndex =i;
			listdataTabs.updateOne(i, 
				{
				    name : jsonTabs[i].name,
				    selected : "1",
				    categoryId : jsonTabs[i].categoryId
				}
			);
		}
		else{
			listdataTabs.updateOne(i, 
				{
				    name : jsonTabs[i].name,
				    selected : "2",
				    categoryId : jsonTabs[i].categoryId
				}
			);
		}
	}
	//do_SegmentView_tabs重新绑定数据
	do_SegmentView_1.refreshItems();
	//移动当选中的cell上
	if (_selectedIndex >=0)	{
		do_SegmentView_1.index = _selectedIndex;	
	}
});

page.on("initCategoryData", function(data){
	listdataTabs.removeAll();
	jsonTabs = data.categoryList;
	listdataTabs.addData(jsonTabs);
	do_SegmentView_1.bindItems(listdataTabs);
	do_SegmentView_1.refreshItems();
});
//显示全部
aLayout_goCateGrid.on("touch", function(){
	page.fire("ShopRefreshCategory", listdataTabs);
	page.fire("ShopShowAllCategory");
});